package com.wms.uitl;

import java.io.StringWriter;
import java.util.Map;

import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.stereotype.Component;

@Component
public class ConvertJson2PoJo {
	
	private static final ObjectMapper om = new ObjectMapper();//jackson 转换器，将object 转换成json string
	
	
	//convert to domain   		Domain domain = objectMapper.readValue(json, Domain.class);
	//convert to domain[] 		Domain[] domains = objectMapper.readValue(json, Domain[].class);
	//convert to map			Map<String, Map<String, Object>> maps = objectMapper.readValue(json, Map.class);
	//convert to list		    List<LinkedHashMap<String, Object>> list = objectMapper.readValue(json, List.class);
	private void convert(Object obj, Class clazz, String json)throws Exception{
		
		try{
			obj = om.readValue(json, clazz);//进行转换
			
		}catch (Exception e){
			e.printStackTrace();
			throw new Exception(e);
		}
	}
	
	
	
}
